﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FreeAccessNetdisk.src.classes
{
    public class Downloader : IOperator

    {
        private readonly CloudClient _cloudClient;

        private string _targetDir;
        
        public Downloader(CloudClient cloudClient, string targetDir)
        {
            _cloudClient = cloudClient;
            _targetDir = targetDir;
        }

        public void CreateFile(ChangeFileInfo changeFile)
        {
            string localFileDir = Path.Combine(_targetDir, changeFile.FileDir);
            _cloudClient.GetObject(changeFile.FileDir, localFileDir);
        }

        public void DeleteFile(ChangeFileInfo changeFile)
        {
            string localFileDir = Path.Combine(_targetDir, changeFile.FileDir);
            File.Delete(localFileDir);
        }

        public void ChangeFile(ChangeFileInfo changeFile)
        {
            DeleteFile(changeFile);
            CreateFile(changeFile);
        }

        public void SetTargetDir(string targetDir)
        {
            this._targetDir = targetDir;
        }
    }
}
